<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *参与记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'all';
$tabs=array(
	array('op'=>'all','title'=>'累积统计'),
	array('op'=>'list','title'=>'金豆记录'),
	array('op'=>'listday','title'=>'日金豆统计'),
	array('op'=>'listmonth','title'=>'月金豆统计'),
);
if($_RQ['op']=='all'){
	$params=array('ratefee >'=>0,'credit_type'=>1,'isqingratefee'=>0,'paystatus'=>1,'merchid'=>$_SESSION['onemerchid']);
	$params['uniacid']=$_SESSION['uniacid'];
	$item=array();
	$item['ratefee']=pdo_getsum('jy_creditshop_log',$params,'ratefee');
	$return['list'][0]=$item;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'ratefee','title'=>'积分累积手续费总额','type'=>'string'),
		),'action'=>array(
			array('type'=>'post','op'=>'isqingratefee','title'=>'清空累积'),
		)),
	);
	$return['credit_type']=credit_types();
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('ratefee >'=>0,'credit_type'=>3,'merchid'=>$_SESSION['onemerchid']);
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['logno'])){
		$params['logno like']='%'.trim($_RQ['logno']).'%';
		$return['params']['logno']=$_RQ['logno'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','total','ratefee','mid','merchid','type','address','addressid','goodsid','money','credit','credit_type','logno','paystatus','status','dispatchstatus','remark','createtime');
	$list=pdo_getslice('jy_creditshop_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
				$item['title']=pdo_getcolumn('jy_creditshop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']),'title');
				$item['goods_thumb']=pdo_getcolumn('jy_creditshop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']),'thumb');
				$item['member']=cfc('core')->member_show($item['mid']);
				if($item['addressid'] || $item['address']){
					$item['isaddress']=1;
				}
				$item['total']=$item['total']?:1;
				$item['merchname']=pdo_getcolumn('jy_merch_user',array('id'=>$item['merchid']),'merchname');
				$item['merchname']=$item['merchname']?:'无';
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'logno','title'=>'参与记录编号','type'=>'string'),
			array('type'=>'img_string','title'=>'商品名称_Goods','img'=>'goods_thumb',
			'data'=>array(
				array('title'=>'','name'=>'title'),
				)
			),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'merchname','title'=>'所属商户','type'=>'string'),
			array('name'=>'credit_type','title'=>'类型','type'=>'radio','options'=>'credit_type'),
			array('name'=>'ratefee','title'=>'手续费','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'参与时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'logno','title'=>'参与记录编号','type'=>'string','width'=>'15'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status','width'=>'15'),
		)
		
	);
	$return['credit_type']=credit_types();
	$return['status']=$this->order_status;
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='listday'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid']);
	if(!empty($_RQ['merchname'])){
		$params['merchname like']='%'.trim($_RQ['merchname']).'%';
		$return['params']['merchname']=$_RQ['merchname'];
	}
	if(!empty($_RQ['realname'])){
		$params['realname like']='%'.trim($_RQ['realname']).'%';
		$return['params']['realname']=$_RQ['realname'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=intval($_RQ['mobile']);
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if($_RQ['status']!=''){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$fields=array('id','mid','star','isrecommand','salecate','cateid','mobile','realname','status','jointime','accounttime','logo','merchname');
    $orderby='star desc, id desc';
	$total='';
	$list=pdo_getslice('jy_merch_user',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$day=$_RQ['day']?strtotime($_RQ['day']):mktime(0,0,0,date('m'),date('d'),date('Y'));
	$return['params']['day']=date('Y-m-d',$day);
	$starttime=$day;
	$endtime=$starttime+24*3600;
	$params=array('credit_type'=>3,'uniacid'=>$_SESSION['uniacid'],'paystatus'=>1);
	foreach($list as &$v){
		$v['catename']=pdo_getcolumn('jy_merch_category',array('id'=>$v['cateid'],'uniacid'=>$_SESSION['uniacid']),'catename');
		$params['createtime between']=array($starttime,$endtime);
		$params['merchid']=intval($v['id']);
		$v['fee']=pdo_getsum('jy_creditshop_log',$params,'ratefee');
		$v['fee']=$v['fee']?:0;
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
				array('name'=>'star','title'=>'星数_Star','type'=>'star','set'=>'star'),
				array('title'=>'商户信息_Merch','type'=>'img_string','img'=>'logo',
				'data'=>array(
					array('title'=>'名称：','name'=>'merchname'),
					array('title'=>'项目：','name'=>'salecate')
					)
				),
				array('name'=>'catename','title'=>'所属分类','type'=>'string'),
				array('name'=>'fee','title'=>'手续费额度','type'=>'unitstring','unit'=>'个'),
				array('name'=>'jointime','title'=>'入驻时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'merchname','width'=>15,'title'=>'商户名称','type'=>'string'),
			array('name'=>'day','width'=>10,'title'=>'日期','type'=>'time'),
		)
	);
	$return['htmls']=$htmls;
	$nowy=date('Y');
	$y1=$nowy-2;
	$y2=$nowy-1;
	$return['ys']=array(
		$y1=>$y1.'年',
		$y2=>$y2.'年',
		$nowy=>$nowy.'年',
	);
	$return['months']=array(
		'1'=>'1月',
		'2'=>'2月',
		'3'=>'3月',
		'4'=>'4月',
		'5'=>'5月',
		'6'=>'6月',
		'7'=>'7月',
		'8'=>'8月',
		'9'=>'9月',
		'10'=>'10月',
		'11'=>'11月',
		'12'=>'12月',
	);
	exi($return);
}
if($_RQ['op']=='listmonth'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid']);
	if(!empty($_RQ['merchname'])){
		$params['merchname like']='%'.trim($_RQ['merchname']).'%';
		$return['params']['merchname']=$_RQ['merchname'];
	}
	if(!empty($_RQ['realname'])){
		$params['realname like']='%'.trim($_RQ['realname']).'%';
		$return['params']['realname']=$_RQ['realname'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=intval($_RQ['mobile']);
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if($_RQ['status']!=''){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$fields=array('id','mid','star','isrecommand','salecate','cateid','mobile','realname','status','jointime','accounttime','logo','merchname');
    $orderby='star desc, id desc';
	$total='';
	$return['list']=pdo_getslice('jy_merch_user',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$y=$_RQ['y']?:date('Y');
	$m=$_RQ['m']?:date('m');
	$return['params']['y']=$y;
	$return['params']['m']=$m;
	$starttime=strtotime($y.'-'.$m);
	$endtime=strtotime($y.'-'.$m+1);
	$params=array('credit_type'=>3,'uniacid'=>$_SESSION['uniacid'],'paystatus'=>1);
	foreach($list as &$v){
		$v['catename']=pdo_getcolumn('jy_merch_category',array('id'=>$v['cateid'],'uniacid'=>$_SESSION['uniacid']),'catename');
		$params['createtime between']=array($starttime,$endtime);
		$params['merchid']=intval($v['id']);
		$v['fee']=pdo_getsum('jy_creditshop_log',$params,'ratefee');
		$v['fee']=$v['fee']?:0;
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
				array('name'=>'star','title'=>'星数_Star','type'=>'star','set'=>'star'),
				array('title'=>'商户信息_Merch','type'=>'img_string','img'=>'logo',
				'data'=>array(
					array('title'=>'名称：','name'=>'merchname'),
					array('title'=>'项目：','name'=>'salecate')
					)
				),
				array('name'=>'catename','title'=>'所属分类','type'=>'string'),
				array('name'=>'fee','title'=>'手续费额度','type'=>'unitstring','unit'=>'个'),
				array('name'=>'jointime','title'=>'入驻时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'merchname','width'=>15,'title'=>'商户名称','type'=>'string'),
			array('name'=>'y','width'=>15,'title'=>'年份','type'=>'radio','options'=>'ys'),
			array('name'=>'m','width'=>15,'title'=>'月份','type'=>'radio','options'=>'months'),
		)
	);
	$return['htmls']=$htmls;
	$nowy=date('Y');
	$y1=$nowy-2;
	$y2=$nowy-1;
	$return['ys']=array(
		$y1=>$y1.'年',
		$y2=>$y2.'年',
		$nowy=>$nowy.'年',
	);
	$return['months']=array(
		'01'=>'1月',
		'02'=>'2月',
		'03'=>'3月',
		'04'=>'4月',
		'05'=>'5月',
		'06'=>'6月',
		'07'=>'7月',
		'08'=>'8月',
		'09'=>'9月',
		'10'=>'10月',
		'11'=>'11月',
		'12'=>'12月',
	);
	exi($return);
}
if($_RQ['op']=='isqingratefee'){
	$params=array('ratefee >'=>0,'credit_type'=>3,'isqingratefee'=>0,'paystatus'=>1,'merchid'=>$_SESSION['onemerchid']);
	$params['uniacid']=$_SESSION['uniacid'];
	pdo_update('jy_creditshop_log',array('isqingratefee'=>1),$params);
	exi('清空累积成功！');
}